<?php

namespace App\Http\Controllers\Backend;

use App\DataTables\ChannelVisitDayDataTable;
use App\Http\Requests;
use App\Http\Requests\CreateChannelVisitDayRequest;
use App\Http\Requests\UpdateChannelVisitDayRequest;
use App\Repositories\ChannelVisitDayRepository;
use Flash;
use App\Http\Controllers\AppBaseController;
use Response;

class ChannelVisitDayController extends AppBaseController
{
    /** @var  ChannelVisitDayRepository */
    private $channelVisitDayRepository;

    public function __construct(ChannelVisitDayRepository $channelVisitDayRepo)
    {
        $this->channelVisitDayRepository = $channelVisitDayRepo;
    }

    /**
     * Display a listing of the ChannelVisitDay.
     *
     * @param ChannelVisitDayDataTable $channelVisitDayDataTable
     * @return Response
     */
    public function index(ChannelVisitDayDataTable $channelVisitDayDataTable)
    {
        return $channelVisitDayDataTable->render('backend.channel_visit_days.index');
    }

    /**
     * Show the form for creating a new ChannelVisitDay.
     *
     * @return Response
     */
    public function create()
    {
        return view('backend.channel_visit_days.create');
    }

    /**
     * Store a newly created ChannelVisitDay in storage.
     *
     * @param CreateChannelVisitDayRequest $request
     *
     * @return Response
     */
    public function store(CreateChannelVisitDayRequest $request)
    {
        $input = $request->all();

        $channelVisitDay = $this->channelVisitDayRepository->create($input);

        Flash::success(trans('flash.controller.save_success', ['model' => 'Channel Visit Day']));

        return redirect(route('channelVisitDays.index'));
    }

    /**
     * Display the specified ChannelVisitDay.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $channelVisitDay = $this->channelVisitDayRepository->findWithoutFail($id);

        if (empty($channelVisitDay)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Visit Day']));

            return redirect(route('channelVisitDays.index'));
        }

        return view('backend.channel_visit_days.show')->with('channelVisitDay', $channelVisitDay);
    }

    /**
     * Show the form for editing the specified ChannelVisitDay.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $channelVisitDay = $this->channelVisitDayRepository->findWithoutFail($id);

        if (empty($channelVisitDay)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Visit Day']));

            return redirect(route('channelVisitDays.index'));
        }

        return view('backend.channel_visit_days.edit')->with('channelVisitDay', $channelVisitDay);
    }

    /**
     * Update the specified ChannelVisitDay in storage.
     *
     * @param  int              $id
     * @param UpdateChannelVisitDayRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateChannelVisitDayRequest $request)
    {
        $channelVisitDay = $this->channelVisitDayRepository->findWithoutFail($id);

        if (empty($channelVisitDay)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Visit Day']));

            return redirect(route('channelVisitDays.index'));
        }

        $channelVisitDay = $this->channelVisitDayRepository->update($request->all(), $id);

        Flash::success(trans('flash.controller.update_success', ['model' => 'Channel Visit Day']));

        return redirect(route('channelVisitDays.index'));
    }

    /**
     * Remove the specified ChannelVisitDay from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $channelVisitDay = $this->channelVisitDayRepository->findWithoutFail($id);

        if (empty($channelVisitDay)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Visit Day']));

            return redirect(route('channelVisitDays.index'));
        }

        $this->channelVisitDayRepository->delete($id);

        Flash::success(trans('flash.controller.delete_success', ['model' => 'Channel Visit Day']));

        return redirect(route('channelVisitDays.index'));
    }
}
